package top.heue.utils.base.base

import android.os.Bundle
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LifecycleEventObserver
import top.heue.utils.base.R
import top.heue.utils.base.util.system.BarUtil
import top.heue.utils.base.util.system.SystemUtil
import top.heue.utils.base.helper.inflate
import top.heue.utils.lifecycle.helper.viewModel
import top.heue.utils.log.L

open class BaseActivity : AppCompatActivity() {
    var isAutoDarkBar = true
    protected open fun onCreate() {}

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //生命周期日志
        lifecycle.addObserver(LifecycleEventObserver { _, event ->
            L.d("Life", "$this\n${event.name}")
        })
        //触发事件
        onCreate()
        if (isAutoDarkBar) {
            val mode = !SystemUtil.isDarkMode(this)
            BarUtil.setMode(this, mode)
        }
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        L.d("Life", "$this\nonDetachedFromWindow")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        L.d("Life", "$this\nonSaveInstanceState")
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        L.d("Life", "$this\nonRestoreInstanceState")
    }
}